USE GESTION2
go
IF OBJECT_ID('dbo.WASP_D0006_CREA_TABLA_DE_PENSIONADOS') IS NOT NULL
BEGIN
    DROP PROCEDURE dbo.WASP_D0006_CREA_TABLA_DE_PENSIONADOS
    IF OBJECT_ID('dbo.WASP_D0006_CREA_TABLA_DE_PENSIONADOS') IS NOT NULL
        PRINT '<<< FAILED DROPPING PROCEDURE dbo.WASP_D0006_CREA_TABLA_DE_PENSIONADOS >>>'
    ELSE
        PRINT '<<< DROPPED PROCEDURE dbo.WASP_D0006_CREA_TABLA_DE_PENSIONADOS >>>'
END
go
SET ANSI_NULLS ON
go
SET QUOTED_IDENTIFIER ON
go
CREATE PROCEDURE [dbo].[WASP_D0006_CREA_TABLA_DE_PENSIONADOS]
AS

if exists (select * from dbo.sysobjects where id = object_id(N'[PENPF000]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [PENPF000]

select RUTTRABAJA, CODAGENCIA, CLVEMPRESA, CAJPREVTRA, CIVILPEN, z07310dsc as CIUDADPEN, REGIONPEN, POSTALPEN, TLFONOPEN, IDENTIPAG, TIPODEPEN, GLOSDEPEN, FVECTOPAC, RENTATRABA, MONEDAPEN, AGEINGRES0, FCONTTRABA, FINGRTRABA, FDESATRABA, FCANBEMTRA, FCESATRABA, CCAFANT, ENTIDANTE, EJECUTIVO, ESTADOTRAB, STSCESTRAN, STSCSOTRAB, FECREAREC, USCREAREC, RSTFILLER, FMODIFREG, STSMODREG, USRMODREG, CTABT 
into dbo.PENPF000 
from
    penpf000_temp cre Left Join z07310 com (nolock) ON
    cre.CIUDADPEN = com.z07310com
-- penpf000_temp cre, z07310 com (nolock) 
--where cre.CIUDADPEN *= com.z07310com
go
SET ANSI_NULLS OFF
go
SET QUOTED_IDENTIFIER OFF
go
IF OBJECT_ID('dbo.WASP_D0006_CREA_TABLA_DE_PENSIONADOS') IS NOT NULL
    PRINT '<<< CREATED PROCEDURE dbo.WASP_D0006_CREA_TABLA_DE_PENSIONADOS >>>'
ELSE
    PRINT '<<< FAILED CREATING PROCEDURE dbo.WASP_D0006_CREA_TABLA_DE_PENSIONADOS >>>'
go
